/*
 * SubmitCharacterWindow.java
 *
 * Created on September 5, 2008, 4:27 PM
 */
package com.lct.eq2.gui;

import com.lct.eq2.data.Line;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;

/**
 *
 * @author  waite
 */
public class JoinGroup extends javax.swing.JFrame {
    private LiteGui parent;

    /** Creates new form SubmitCharacterWindow */
    public JoinGroup(LiteGui parent) {
        this.parent = parent;
        initComponents();
        this.setIconImage(Toolkit.getDefaultToolkit().getImage("WAR.gif"));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Submit");

        jButton1.setText("Join");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextField1KeyPressed(evt);
            }
        });

        jLabel1.setText("Join Whose Group?");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 136, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jButton1))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButton1)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    //this.parent.sendData("::joingroup::" + this.parent.characterID + ";;" + this.jTextField1.getText().toLowerCase());
    Line line = new Line("", Line.PARTY_JOIN);
    line.setCharacter(this.parent.getMainCharacter());
    line.setServer(this.parent.getServer());
    line.setGroupID(line.getServer().toLowerCase() + "\\" + this.jTextField1.getText().toLowerCase());
    this.parent.sendData(line);
    
    //JOptionPane.showMessageDialog(null, "You have joined " + this.jTextField1.getText() + "'s group.",
    //        "Joined", JOptionPane.INFORMATION_MESSAGE);
    //this.parent.setInGroup(true);
    this.setVisible(false);
    this.dispose();
}//GEN-LAST:event_jButton1ActionPerformed

private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        Line line = new Line("", Line.PARTY_JOIN);
        line.setCharacter(this.parent.getMainCharacter());
        line.setServer(this.parent.getServer());
        line.setGroupID(line.getServer().toLowerCase() + "\\" + this.jTextField1.getText().toLowerCase());
        this.parent.sendData(line);

        //JOptionPane.showMessageDialog(null, "You have joined " + this.jTextField1.getText() + "'s group.",
        //        "Joined", JOptionPane.INFORMATION_MESSAGE);
        //this.parent.setInGroup(true);
        this.setVisible(false);
        this.dispose();
    }
}//GEN-LAST:event_jTextField1KeyPressed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
}
